package com.jy.app.lib.utils;

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.CycleInterpolator;
import android.view.animation.TranslateAnimation;

public class AnimUtils {
    /**
     * 晃动动画
     * @param counts  1秒钟晃动多少下
     * @return
     */
    public static Animation shakeAnimation(int counts) {
        Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
        //设置一个循环加速器，使用传入的次数就会出现摆动的效果。
        translateAnimation.setInterpolator(new CycleInterpolator(counts));
        translateAnimation.setDuration(500);
        return translateAnimation;
    }

    /**
     *
     * @param view 需要摇晃的View
     * @param counts 1秒钟晃动多少下
     */
    public static void shakeView(View view,int counts){
        if (view == null) return;
        view.startAnimation(shakeAnimation(counts));
    }

}
